//
//  DYZSelectBrandController.m
//  Demo
//
//  Created by 毕仲阳 on 16/8/18.
//  Copyright © 2016年 mycompany. All rights reserved.
//

#import "DYZSelectBrandController.h"
#import "DYZSelectCarsSeriesController.h"
#import "DSHTTPClient.h"
static NSString *brandID = @"brandID";
@interface DYZSelectBrandController ()
@property(nonatomic,strong)NSArray *loadData;
@property(nonatomic,strong)NSArray *brandIds;
@end

@implementation DYZSelectBrandController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.tableFooterView = [[UIView alloc]init];
    self.tableView.bounces = NO;
    [self type];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:brandID];
    self.navigationItem.title = @"选择品牌";
    //    NSArray *array = @[@{@"carname":@"奔驰"},
    //                       @{@"carname":@"宝马"},
    //                       @{@"carname":@"宾利"},
    //                       @{@"carname":@"劳斯莱斯"}];
    //    self.brandData = array;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//解析车系数据
- (void)type{
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    //"account":"13800111100","pasword":"123456"
    [param setValue:@"1" forKey:@"accountid"];
    [param setValue:@"3" forKey:@"cartype"];
    
    [DSHTTPClient postUrlString:@"http://iosapi.itcast.cn/car/cartypelist.json.php" withParam:param withSuccessBlock:^(NSDictionary * data) {
        
        
        NSDictionary *dict = [data objectForKey:@"data"];
        
        NSMutableArray *array = [NSMutableArray array];
        
        
        NSArray *arr = [dict objectForKey:@"high"];
        
        for (NSDictionary *dict1 in arr) {
            
            NSString *str = [dict1 objectForKey:@"name"];
            
            [array addObject:str];
            
        }
        
        //        NSLog(@"%@",array);
        
        self.loadData = array.copy;
        
        [self.tableView reloadData];
        
    } withFailedBlock:^(NSError *error) {
        NSLog(@"%@",error);
    } withErrorBlock:^(NSString *message) {
        NSLog(@"%@",message);
    }];
    
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 4;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:brandID forIndexPath:indexPath];
    
    // Configure the cell...
    cell.textLabel.text = self.loadData[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    DYZSelectCarsSeriesController *vc = [[DYZSelectCarsSeriesController alloc]init];
    //vc.navigationItem.hidesBackButton = YES;
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
    //    [self.navigationController.navigationBar setBarTintColor:[UIColor darkGrayColor]];
    vc.name = self.loadData[indexPath.row];
    
    if(indexPath.row == 0 || indexPath.row == 2)
    {
        vc.brandId = @"BD1001";
        
    }else if(indexPath.row == 1 || indexPath.row == 3){
        
        vc.brandId = @"BD1002";
    }
    
    
    [self.navigationController.navigationBar setTintColor:[UIColor darkGrayColor]];
    
    [self.navigationController pushViewController:vc animated:YES];
}

@end
